<style scoped>
.policy-edit{
    padding-bottom: 35px;
    
}

.pro-list{
    padding-top: 10px;
}
.pro-list h4{
    display: block;
    position: relative;
}

.pro-list h4:before{
    content: '';
    position: absolute;
    height: 0;
    top:8px;
    left: 0;
    width: 100%;
    border-bottom: 1px dotted #d9d9d9;
    
}
.pro-list h4 span{
    display: inline-block;
    background: #fff;
    padding-left: 5px;
    padding-right: 5px;
    position: relative;
    font-weight: normal;
}
.import-left{
    background-color: #f2f2f2;
}
.import-search{
    padding: 15px 15px 0;
}
.import-list{
    padding: 0 13px;
}
.import-right{
    background-color: #cfebf9;
    padding: 20px 20px 0 20px;
}
.import-right-title{
    overflow: hidden;
}
.import-right-title h3{
    display: inline-block;
    color: #ef8411;
    font-size: 16px;
    line-height: 43px;
}
.import-right-body{
    padding-top: 20px;
}
.import-right-body .ivu-form-item{
    margin-bottom: 15px;
}
.import-search .ivu-input-group-append button{
    background-color: #4074e1;
    color: #fff;
}
.import-search .ivu-input-group{
    top: 0;
}
.pd35{
    padding-bottom: 35px;
}
.form-box{
    position: relative;
    overflow: hidden;
}
.fixed-bottom{
    padding-top: 18px;
    height:80px;
    position:fixed; 
    left:210px;
    right:0; 
    bottom:0; 
    z-index: 999;
    text-align: center;
    background-color: rgb(255, 255, 255); 
    box-shadow: 0px 0px 9px 0px rgba(0, 0, 0, 0.28);
}
.sidehide{
    left: 75px;
}
.benefit{
    margin-bottom: 15px;
}
.reset{
    background-color: #5cadff !important;
}
</style>
<style>
.clearfix:after {
    visibility: hidden;
    display: block;
    content: " ";
    clear: both;
    height: 0;
    line-height: 0;
}

.clearfix {
    zoom: 1;
}
</style>

<template>
    <div class="policy-edit">
        <product-title></product-title>
        <div class="form-box">
            <div class="common-box-header">
                <h3>录单员信息</h3>
                <Button @click="importEmployee(1)" class="fr mt7" type="warning" icon="icon iconfont icon-daoru">导入录单员</Button>
            </div>
            <div class="common-box-body common-form-body">
                <Form ref="entering" :model="entering" :rules="entering_ruleValidate">
                    <Row>
                        <Col :xs="24" :sm="24" :md="6" :lg="6">
                            <FormItem prop="job_code" label="录单工号">
                                <Input type="text" v-model="entering.job_code "  placeholder="请选择" disabled></Input>
                            </FormItem>
                        </Col>
                        <Col :xs="24" :sm="24" :md="6" :lg="6">
                            <FormItem prop="name" label="录单员姓名">                                
                                <Input type="text" v-model="entering.name"  placeholder="请选择" disabled></Input>                               
                            </FormItem>
                        </Col>
                        <Col :xs="24" :sm="24" :md="12" :lg="12">
                            <FormItem prop="datetime" label="录单时间">
                                <DatePicker type="date" placeholder="请选择" v-model="entering.datetime" @on-change="datachange($event,entering,'date')"></DatePicker>
                            </FormItem>
                        </Col>
                    </Row>   
                </Form>
            </div>
            <div class="common-box-header">
                <h3>业务员信息</h3>
                <Button @click="importEmployee(2)" class="fr mt7" type="warning" icon="icon iconfont icon-daoru">导入业务员</Button>
            </div>
            <div class="common-box-body common-form-body">
                <Form ref="agent" :model="agent" :rules="agent_ruleValidate">
                    <Row>
                        <Col :xs="24" :sm="24" :md="6" :lg="6">
                            <FormItem prop="oname" label="机构">
                                <Input type="text" v-model="agent.oname"  placeholder="请选择" disabled></Input>
                            </FormItem>
                        </Col>
                        <Col :xs="24" :sm="24" :md="6" :lg="6">
                            <FormItem prop="dept_name" label="部门">                                
                                <Input type="text" v-model="agent.dept_name"  placeholder="请选择" disabled></Input>                               
                            </FormItem>
                        </Col>
                        <Col :xs="24" :sm="24" :md="6" :lg="6">
                            <FormItem prop="rank_name" label="职级">
                                <Input type="text" v-model="agent.rank_name"  placeholder="请选择" disabled></Input>
                            </FormItem>
                        </Col>
                        <Col :xs="24" :sm="24" :md="6" :lg="6">
                            <FormItem prop="job_code" label="工号">                                
                                <Input type="text" v-model="agent.job_code"  placeholder="请选择" disabled></Input>                               
                            </FormItem>
                        </Col>
                        <Col :xs="24" :sm="24" :md="6" :lg="6">
                            <FormItem prop="name" label="姓名">
                                <Input type="text" v-model="agent.name"  placeholder="请选择" disabled></Input>
                            </FormItem>
                        </Col>
                        <Col :xs="24" :sm="24" :md="6" :lg="6">
                            <FormItem label="关系上属">                                
                                <Input type="text" v-model="agent.leader_name"  placeholder="请选择" disabled></Input>                               
                            </FormItem>
                        </Col>
                        <Col :xs="24" :sm="24" :md="12" :lg="12">
                            <FormItem label="推荐人">                                
                                <Input type="text" v-model="agent.rec_name"  placeholder="请选择" disabled></Input>                               
                            </FormItem>
                        </Col>
                    </Row>   
                </Form>
            </div>
            <div class="common-box-header">
                <h3>保单信息</h3>
            </div>
            <div class="common-box-body common-form-body">
                <Form ref="policyform" :model="policyform" :rules="policy_ruleValidate">
                    <Row>
                        <Col :xs="24" :sm="24" :md="6" :lg="6">
                            <FormItem prop="cid" label="保险公司">
                                <!-- <Select v-model="policyform.cid" @on-change="companychange($event)" filterable remote label-in-value :remote-method="remoteCom" :loading="proloading"  placeholder="选择保险公司">  
                                    <Option v-for="(option, index) in comoptions" :value="option.value" :key="index">{{option.label}}</Option>                               
                                </Select> -->
                                <Select v-model="policyform.cid"  filterable  placeholder="选择保险公司" :transfer=true>  
                                    <Option v-for="(option, index) in comoptions" :value="option.cid" :key="index">{{option.name}}</Option>                               
                                </Select>
                            </FormItem>
                        </Col>
                        <Col :xs="24" :sm="24" :md="6" :lg="6">
                            <FormItem prop="insure_datetime" label="投保日期">
                                    <DatePicker type="date" @on-change="datachange($event,policyform,'insure_date')" v-model="policyform.insure_datetime" placeholder="请选择" :transfer=true placement="top"></DatePicker>  
                            </FormItem>
                        </Col> 
                        <Col :xs="24" :sm="24" :md="6" :lg="6">
                            <FormItem prop="name" label="保险计划">                                
                                <Input type="text" v-model="policyform.name"  placeholder="请选择"></Input>                               
                            </FormItem>
                        </Col>
                        <Col :xs="24" :sm="24" :md="6" :lg="6">
                            <FormItem prop="insure_num" label="投保单号码">
                                <Input type="text" disabled v-model="policyform.insure_num"  placeholder="请输入投保单号码"></Input>   
                            </FormItem>
                        </Col>
                        <Col :xs="24" :sm="24" :md="6" :lg="6">
                            <FormItem prop="pay_period" label="交费期间">
                                <Select v-model="policyform.pay_period" placeholder="请选择">
                                    <Option v-for="item in policypay_period" :value="item">{{item}}</Option>                                   
                                </Select>
                            </FormItem>
                        </Col> 
                        <Col :xs="24" :sm="24" :md="6" :lg="6">
                            <FormItem prop="pay_type" label="交费方式">
                                <Select v-model="policyform.pay_type" placeholder="请选择">
                                    <Option value="期交">期交</Option>
                                    <Option value="一次性交">一次性交</Option>
                                </Select>
                            </FormItem>
                        </Col> 
                        <Col :xs="24" :sm="24" :md="6" :lg="6">
                            <FormItem prop="premium" label="保费">
                                <Input type="text" v-model="policyform.premium"  placeholder="请输入保费"></Input>   
                            </FormItem>
                        </Col>
                        <Col :xs="24" :sm="24" :md="6" :lg="6">
                            <FormItem prop="status" label="保单状态">
                                <Select v-model="policyform.status" placeholder="请选择">
                                    <Option value="1">预收件</Option>
                                    <Option value="3">契撤件</Option>
                                </Select>
                            </FormItem>
                        </Col>
                        <Col :xs="24" :sm="24" :md="6" :lg="6" v-if="statustag">
                            <FormItem   prop="withdraw_datetime" label="撤单时间">
                                    <DatePicker type="date" @on-change="datachange($event,policyform,'withdraw_date')" v-model="policyform.withdraw_datetime" placeholder="请选择" :transfer=true placement="top"></DatePicker>  
                            </FormItem>
                        </Col> 
                        <Col :xs="24" :sm="24" :md="6" :lg="6">
                            <FormItem label="短期消费型">
                                <Select v-model="policyform.is_short"  placeholder="请选择">
                                    <Option value="1">是</Option>
                                    <Option value="2">否</Option>
                                </Select>
                            </FormItem>
                        </Col>                       
                    </Row>   
                </Form>
            </div>
            <div class="common-box-header">
                <h3>客户信息</h3>
            </div>
            <div class="mt20 pro-person">
                <Tabs type="card" :animated=false>
                    <TabPane label="投保人" name="name1">
                        <div class="common-box-header">
                            <h3>投保人</h3>
                            <Button @click="importapplicant(3)" class="fr mt7" type="warning" icon="icon iconfont icon-daoru">导入投保人</Button>
                        </div>
                        <div class="common-box-body common-form-body pd35">
                            <Form ref="applicant" :model="applicant" :rules="applicant_ruleValidate">
                                <Row>                                   
                                    <Col :xs="24" :sm="24" :md="6" :lg="6">
                                        <FormItem prop="name" label="姓名">
                                            <Input type="text" v-model="applicant.name"  placeholder="请输入姓名"></Input>   
                                        </FormItem>
                                    </Col>  
                                    <Col :xs="24" :sm="24" :md="6" :lg="6">
                                        <FormItem prop="cardName" label="证件类型">
                                            <Select  placeholder="请选择证件类型" v-model="applicant.cardName" :transfer=true placement="top">
                                                <Option value="身份证">身份证</Option>
                                                <Option value="护照">护照</Option>
                                                <Option value="军官证">军官证</Option>
                                                <Option value="港澳居民来往内地通行证">港澳居民来往内地通行证 </Option>
                                                <Option value="其他">其他</Option>
                                            </Select>  
                                        </FormItem>
                                    </Col> 
                                    <Col :xs="24" :sm="24" :md="6" :lg="6">
                                        <FormItem prop="cardNum" label="证件号码">
                                            <Input type="text"  placeholder="请输入姓名" v-model="applicant.cardNum"></Input>   
                                        </FormItem>
                                    </Col> 
                                    <Col :xs="24" :sm="24" :md="6" :lg="6">
                                        <FormItem prop="mobile" label="联系电话">
                                            <Input type="text"  placeholder="请输入联系电话" v-model="applicant.mobile"></Input>   
                                        </FormItem>
                                    </Col>
                                    <Col :xs="24" :sm="24" :md="6" :lg="6">
                                        <FormItem prop="sex" label="性别">
                                            <Select  placeholder="请选择性别" v-model="applicant.sex">
                                                <Option value="1">男</Option>
                                                <Option value="2">女</Option>
                                            </Select>   
                                        </FormItem>
                                    </Col>  
                                    <Col :xs="24" :sm="24" :md="6" :lg="6">
                                        <FormItem prop="birthdaytime" label="出生日期">
                                             <DatePicker type="date" @on-change="datachange($event,applicant,'birthday')" v-model="applicant.birthdaytime" placeholder="请选择" :transfer=true placement="top"></DatePicker>  
                                        </FormItem>
                                    </Col> 
                                    <Col :xs="24" :sm="24" :md="6" :lg="6">
                                        <FormItem prop="company" label="工作单位">
                                            <Input type="text" v-model="applicant.company"  placeholder="请输入工作单位"></Input>   
                                        </FormItem>
                                    </Col> 
                                    <Col :xs="24" :sm="24" :md="6" :lg="6">
                                        <FormItem prop="profession" label="职业/工种">
                                            <Input type="text" v-model="applicant.profession" placeholder="请输入职业/工种"></Input>   
                                        </FormItem>
                                    </Col>  
                                    <Col :xs="24" :sm="24" :md="12" :lg="12">
                                        <FormItem prop="home_address" label="详细地址">
                                            <Input type="text" v-model="applicant.home_address" placeholder="请输入详细地址"></Input>   
                                        </FormItem>
                                    </Col> 
                                    <Col :xs="24" :sm="24" :md="6" :lg="6">
                                        <FormItem prop="postcode" label="邮编">
                                            <Input type="text" v-model="applicant.postcode" placeholder="请输入邮编"></Input>   
                                        </FormItem>
                                    </Col> 
                                    <Col :xs="24" :sm="24" :md="6" :lg="6">
                                        <FormItem prop="email" label="Email">
                                            <Input type="text" v-model="applicant.email"  placeholder="请输入Email"></Input>   
                                        </FormItem>
                                    </Col>                                                        
                                </Row>   
                            </Form>
                        </div>
                    </TabPane>
                    <TabPane label="被保人" name="name2">
                        <Form  :model="pitem" ref="insureds" :rules="insured_ruleValidate" v-for="(pitem,pindex) in policyDetail.insureds" >
                            <div class="common-box-header">
                                <h3>被保人</h3>
                                与投保人关系：
                                <RadioGroup v-model="pitem.relation" @on-change="radiochange($event,pindex)">
                                    <Radio label="本人"></Radio>
                                    <Radio label="配偶"></Radio>
                                    <Radio label="父母"></Radio>
                                    <Radio label="子女"></Radio>
                                    <Radio label="其他"></Radio>
                                </RadioGroup>                               
                                <Button class="fr mt7 ml5" @click="delinsured(pindex)" type="error" icon="icon iconfont icon-shanchu"></Button>
                                <Button class="fr mt7 ml5" type="warning" icon="icon iconfont icon-daoru">导入被保人</Button>
                                <Button class="fr mt7" @click="addinsured" type="primary" icon="icon iconfont icon-addOnly">追加被保人</Button>                           
                            </div>
                            <div class="common-box-body common-form-body" v-show="!pitem.canedit">                           
                                <Row>                                   
                                    <Col :xs="24" :sm="24" :md="6" :lg="6">
                                        <FormItem prop="name" label="姓名">
                                            <Input type="text" v-model="pitem.name"  placeholder="请输入姓名"></Input>   
                                        </FormItem>
                                    </Col>  
                                    <Col :xs="24" :sm="24" :md="6" :lg="6">
                                        <FormItem prop="cardName" label="证件类型">
                                            <Select  placeholder="请选择证件类型"  v-model="pitem.cardName" >
                                                <Option value="身份证">身份证</Option>
                                                <Option value="护照">护照</Option>
                                                <Option value="军官证">军官证</Option>
                                                <Option value="港澳居民来往内地通行证">港澳居民来往内地通行证</Option>
                                                <Option value="其他">其他</Option>
                                            </Select>  
                                        </FormItem>
                                    </Col> 
                                    <Col :xs="24" :sm="24" :md="6" :lg="6">
                                        <FormItem prop="cardNum" label="证件号码">
                                            <Input type="text"  v-model="pitem.cardNum" placeholder="请输入姓名"></Input>   
                                        </FormItem>
                                    </Col> 
                                    <Col :xs="24" :sm="24" :md="6" :lg="6">
                                        <FormItem prop="mobile" label="联系电话">
                                            <Input type="text"  v-model="pitem.mobile"  placeholder="请输入姓名"></Input>   
                                        </FormItem>
                                    </Col>
                                    <Col :xs="24" :sm="24" :md="6" :lg="6">
                                        <FormItem prop="sex" label="性别">
                                            <Select  placeholder="请选择性别"  v-model="pitem.sex">
                                                <Option value="1">男</Option>
                                                <Option value="2">女</Option>
                                            </Select>   
                                        </FormItem>
                                    </Col>  
                                    <Col :xs="24" :sm="24" :md="6" :lg="6">
                                        <FormItem prop="birthdaytime" label="出生日期">
                                            <DatePicker type="date"  @on-change="datachange($event,pitem,'birthday')"  v-model="pitem.birthdaytime" placeholder="请选择"></DatePicker>  
                                        </FormItem>
                                    </Col> 
                                    <Col :xs="24" :sm="24" :md="6" :lg="6">
                                        <FormItem prop="company" label="工作单位">
                                            <Input type="text"  v-model="pitem.company"  placeholder="请输入工作单位"></Input>   
                                        </FormItem>
                                    </Col> 
                                    <Col :xs="24" :sm="24" :md="6" :lg="6">
                                        <FormItem prop="profession" label="职业/工种">
                                            <Input type="text"  v-model="pitem.profession"  placeholder="请输入职业/工种"></Input>   
                                        </FormItem>
                                    </Col>                                                                                          
                                </Row>                              
                            </div>

                            <div class="pro-list" v-for="(sitem,sindex) in pitem.insurances" >
                                <h4>
                                    <span>保障内容</span>
                                </h4>
                                <div class="pro-con">
                                    <Row>
                                        <Col :xs="24" :sm="24" :md="20" :lg="20" offset="1">
                                            <div class="common-box-body common-form-body">                                                
                                                <Row>                                         
                                                    <Col :xs="24" :sm="24" :md="8" :lg="8">
                                                        <FormItem label="险种名称"  :prop="'insurances.' + sindex + '.mongo_id'"
                            :rules="{required: true, message: '险种名称不能为空', trigger: 'change'}">
                                                            <Select v-model="sitem.mongo_id" :label="sitem.name"  @on-change="prochange($event,pindex,sindex)" filterable label-in-value remote :remote-method="remoteMethod1" :loading="proloading"  placeholder="请选择险种名称">
                                                                <!-- <Option value="beijing">New York</Option> -->
                                                                <Option v-for="(option, index) in options1" :value="option.value" :key="index">{{option.label}}</Option>
                                                            </Select>  
                                                        </FormItem>
                                                    </Col>
                                                    <Col :xs="24" :sm="24" :md="8" :lg="8">
                                                        <FormItem label="保险期间" :prop="'insurances.' + sindex + '.period'"
                            :rules="{required: true, message: '保险期间不能为空', trigger: 'change'}">
                                                            <Select v-model="sitem.period"  placeholder="请选择">
                                                                <Option v-for="item in sitem.period_arry" :key="item" :value="item">{{item}}</Option>
                                                            </Select>  
                                                        </FormItem>
                                                    </Col>
                                                    <Col :xs="24" :sm="24" :md="8" :lg="8">
                                                        <FormItem label="交费期间" :prop="'insurances.' + sindex + '.pay_period'"
                            :rules="{required: true, message: '交费期间不能为空', trigger: 'change'}">
                                                            <Select v-model="sitem.pay_period" placeholder="请选择">
                                                                <Option v-for="item in sitem.pay_period_arry" :key="item" :value="item">{{item}}</Option>
                                                            </Select>  
                                                        </FormItem>
                                                    </Col> 
                                                    <Col :xs="24" :sm="24" :md="8" :lg="8">
                                                        <FormItem label="保费" :prop="'insurances.' + sindex + '.premium'"
                            :rules="{required: true,type:'number',transform(value) {return parseFloat(value);}, message: '保费不能为空', trigger: 'blur,change'}">
                                                            <Input type="text" v-model="sitem.premium" placeholder="请输入保费"></Input>   
                                                        </FormItem>
                                                    </Col>
                                                    <Col :xs="24" :sm="24" :md="16" :lg="16" class="input-select">
                                                        <FormItem   :prop="'insurances.' + sindex + '.amount'"
                            :rules="{required: true,type:'number',transform(value) {return parseFloat(value);}, message: '该项不能为空', trigger: 'blur,change'}">
                                                            <Input v-model="sitem.amount" >
                                                                <Select v-model="sitem.type" slot="prepend" style="width:120px">
                                                                    <Option value="保险金额">保险金额</Option>
                                                                    <Option value="档次/计划">档次/计划</Option>
                                                                    <Option value="日额">日额</Option>
                                                                    <Option value="份数">份数</Option>
                                                                </Select>
                                                            </Input>    
                                                        </FormItem>
                                                    </Col>                                                                                    
                                                </Row>                                              
                                            </div>
                                        </Col>
                                        <Col :xs="24" :sm="24" :md="3" :lg="3" class="pro-action">
                                            <Button class="fr mt7 ml20" @click="delpro(pindex,sindex)" type="warning" icon="icon iconfont icon-guanbi"></Button>
                                            <Button class="fr mt7 ml5" @click="addpro(pindex,sindex)" type="primary" icon="icon iconfont icon-addOnly"></Button>
                                        </Col>
                                    </Row>                               
                                </div>
                            </div>
                            <div class="benefit">
                                <Row>
                                    <Col :xs="24" :sm="24" :md="23" :lg="23" offset="1">
                                        <div class="common-box-header">
                                            <h3>受益人</h3>
                                            受益方式：
                                            <RadioGroup v-model="pitem.beneficiary_type" @on-change="benefitchange($event,pindex)">
                                                <Radio label="指定受益"></Radio>
                                                <Radio label="法定受益"></Radio>                                            
                                            </RadioGroup>
                                            <!-- <Button class="fr mt7 ml5" @click="delbenefit(pindex)" type="error" icon="icon iconfont icon-shanchu"></Button>
                                            <Button class="fr mt7" @click="addbenefit(pindex)" type="primary" icon="icon iconfont icon-addOnly"></Button>                            -->
                                        </div>
                                    </Col>
                                </Row>
                                <Row v-for="(bitem,bindex) in pitem.beneficiary" >
                                    <Col :xs="24" :sm="24" :md="20" :lg="20" offset="1">
                                        <div class="common-box-body common-form-body">                                            
                                            <Row>                                         
                                                <Col :xs="24" :sm="24" :md="8" :lg="8">
                                                    <FormItem label="姓名" :prop="'beneficiary.' + bindex + '.name'"
                            :rules="{required: true, message: '姓名不能为空', trigger: 'blur'}">
                                                        <Input type="text"  v-model="bitem.name" placeholder="请输入姓名"></Input> 
                                                    </FormItem>
                                                </Col>
                                                <Col :xs="24" :sm="24" :md="8" :lg="8">
                                                    <FormItem label="证件类型" :prop="'beneficiary.' + bindex + '.cardName'"
                            :rules="{required: true,  message: '证件类型不能为空', trigger: 'blur,change'}">
                                                        <Select  placeholder="请选择证件类型" v-model="bitem.cardName" :transfer=true placement="top">
                                                            <Option value="身份证">身份证</Option>
                                                            <Option value="护照">护照</Option>
                                                            <Option value="军官证">军官证</Option>
                                                            <Option value="港澳居民来往内地通行证">港澳居民来往内地通行证</Option>
                                                            <Option value="其他">其他</Option>
                                                        </Select>  
                                                    </FormItem>
                                                </Col>
                                                <Col :xs="24" :sm="24" :md="8" :lg="8">
                                                    <FormItem label="证件号码"  :prop="'beneficiary.' + bindex + '.cardNum'"
                            :rules="{required: true, pattern: /^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/, message: '证件号码不能为空', trigger: 'blur'}">
                                                        <Input type="text" v-model="bitem.cardNum"  placeholder="请输入证件号码"></Input>  
                                                    </FormItem>
                                                </Col>
                                                <Col :xs="24" :sm="24" :md="8" :lg="8">
                                                    <FormItem label="性别">
                                                        <Select  placeholder="请选择性别" v-model="bitem.sex" :transfer=true placement="top">
                                                            <Option value="1">男</Option>
                                                            <Option value="2">女</Option>                                                            
                                                        </Select>  
                                                    </FormItem>
                                                </Col> 
                                                <Col :xs="24" :sm="24" :md="8" :lg="8">
                                                    <FormItem label="出生日期">
                                                        <DatePicker type="date" @on-change="datachange($event,bitem,'birthday')" v-model="bitem.birthdaytime" placeholder="请选择" :transfer=true placement="top"></DatePicker> 
                                                    </FormItem>
                                                </Col>                                                
                                                <Col :xs="24" :sm="24" :md="8" :lg="8">
                                                    <FormItem  label="与被保人关系">
                                                        <Select  placeholder="请选择与被保人关系" :transfer=true placement="top" v-model="bitem.relation">
                                                            <Option value="1">本人</Option>
                                                            <Option value="2">配偶</Option>
                                                            <Option value="3">父母</Option>
                                                            <Option value="4">子女</Option>
                                                            <Option value="5">其他</Option>
                                                        </Select>   
                                                    </FormItem>
                                                </Col>
                                                <Col :xs="24" :sm="24" :md="8" :lg="12">
                                                    <FormItem label="受益顺序">
                                                        <Select v-model="bitem.order" placeholder="请选择受益顺序" :transfer=true placement="top">
                                                            <Option value="beijing">1</Option>
                                                            <Option value="shanghai">2</Option>
                                                            <Option value="shenzhen">3</Option>
                                                        </Select>   
                                                    </FormItem>
                                                </Col>
                                                <Col :xs="24" :sm="24" :md="8" :lg="12">
                                                    <FormItem prop="scale" label="受益比例">
                                                        <Input type="text" v-model="bitem.scale"  placeholder="请输入受益比例"></Input>   
                                                    </FormItem>
                                                </Col>                                                                                   
                                            </Row>                                           
                                        </div>
                                    </Col>
                                    <Col :xs="24" :sm="24" :md="3" :lg="3" class="pro-action">
                                        <Button class="fr mt7 ml20" @click="delbenefit(pindex,bindex)" type="error" icon="icon iconfont icon-shanchu"></Button>
                                        <Button class="fr mt7" @click="addbenefit(pindex)" type="primary" icon="icon iconfont icon-addOnly"></Button>
                                    </Col>
                                </Row>
                            </div>
                        </Form>
                    </TabPane>
                </Tabs>
            </div>
            <div :class="slidetoggle?'fixed-bottom':'fixed-bottom sidehide' ">
                <Button type="primary" @click="sendpolicy" shape="circle" icon="icon iconfont icon-dui">提交保单信息</Button>
                <Button type="primary" @click="resetform" class="ml20 reset" shape="circle" icon="icon iconfont icon-tableresetpassword">重置</Button>
            </div> 
        </div>
        
        <Modal v-model="addcustomer" :mask-closable='closeable' width="860" title="新增客户" @on-ok="surebtn" :loading="loading">
            <div class="common-box-body common-form-body">   
                <Form>                           
                    <Row>
                        <Col span="12">
                            <Form-item label="姓名">
                                <Input  placeholder="请输入姓名"></Input>
                            </Form-item>                           
                        </Col>
                        <Col span="12">
                            <Form-item label="性别">
                                <Select  placeholder="请选择性别">
                                    <Option value="beijing">1</Option>
                                    <Option value="shanghai">2</Option>
                                    <Option value="shenzhen">3</Option>
                                </Select>  
                            </Form-item>                          
                        </Col>
                        <Col span="12">
                            <Form-item label="证件类型">
                                <Select  placeholder="请选择证件类型">
                                    <Option value="beijing">1</Option>
                                    <Option value="shanghai">2</Option>
                                    <Option value="shenzhen">3</Option>
                                </Select>  
                            </Form-item>                          
                        </Col>
                        <Col span="12">
                            <Form-item label="证件号码">
                                <Input   placeholder="请输入证件号码"></Input>
                            </Form-item>                           
                        </Col>
                        <Col span="12">
                            <Form-item label="联系电话">
                                <Input   placeholder="请输入联系电话"></Input>
                            </Form-item>                           
                        </Col>
                        <Col span="12">
                            <Form-item label="联系电话">
                                <DatePicker type="date" placeholder="请选择"></DatePicker>  
                            </Form-item>                           
                        </Col>
                        <Col span="12">
                            <Form-item label="工作单位">
                                <Input  placeholder="请输入工作单位"></Input>
                            </Form-item>                           
                        </Col>
                        <Col span="12">
                            <Form-item label="职业/工种">
                                <Input   placeholder="请输入职业/工种"></Input>
                            </Form-item>                           
                        </Col>
                        <Col span="12">
                            <Form-item label="邮编">
                                <Input  placeholder="请输入邮编"></Input>
                            </Form-item>                           
                        </Col>
                        <Col span="12">
                            <Form-item label="Email">
                                <Input   placeholder="请输入Email"></Input>
                            </Form-item>                           
                        </Col>
                        <Col span="24">
                            <Form-item label="详细地址">
                                <Input  placeholder="请输入详细地址"></Input>
                            </Form-item>                           
                        </Col>
                    </Row>
                </Form>                
            </div> 
            <div slot="footer" class="modal-footer">
                <Button class="fr mt7 ml5" type="ghost">取消</Button>
                <Button class="fr mt7" type="primary">确定</Button>                
            </div>          
        </Modal>
        <Modal v-model="importcustomer" :mask-closable='closeable' width="860" title="导入客户信息" @on-ok="surebtn" :loading="loading">
            <div class="modal-body">            
                <Row>
                    <Col span="12">
                        <div class="import-left">
                            <div class="common-box-body">
                                <div class="import-search">
                                    <Form ref="formInline">
                                        <Form-item label="姓名">
                                            <Input v-model="searchcustom" placeholder="请输入姓名">
                                                <Button @click="getcustomer" slot="append" type="primary" icon="icon iconfont icon-sousuo"></Button>
                                            </Input>
                                        </Form-item> 
                                    </Form>
                                </div> 
                                <div class="import-list">
                                    <Table :show-header=false stripe height="415" :columns="columnsuser" :data="userlist"></Table>
                                </div>                             
                            </div>
                        </div> 
                    </Col>
                    <Col span="12">
                        <div class="import-right">
                            <div class="import-right-title">
                                <h3>详细信息</h3>
                                <!-- <Button class="fr mt7 ml5" type="warning">编辑</Button>
                                <Button class="fr mt7" type="success">保存</Button>   -->
                            </div>
                            <div class="import-right-body">
                                <div class="common-box-body">
                                    <Form ref="formInline">
                                        <Row>
                                            <Col span="12">
                                                <Form-item label="姓名">
                                                    <Input :disabled="canedit" placeholder="请输入姓名"></Input>
                                                </Form-item>                                                
                                            </Col>
                                            <Col span="12">
                                                <Form-item label="性别">
                                                    <Select :disabled="canedit"  placeholder="请选择性别">
                                                        <Option value="beijing">1</Option>
                                                        <Option value="shanghai">2</Option>
                                                    </Select>  
                                                </Form-item> 
                                            </Col>
                                            <Col span="24">
                                                <Form-item label="证件类型">
                                                    <Select :disabled="canedit"  placeholder="请选择证件类型">
                                                        <Option value="beijing">1</Option>
                                                        <Option value="shanghai">2</Option>
                                                    </Select>  
                                                </Form-item> 
                                            </Col>
                                            <Col span="24">
                                                <Form-item label="证件号码">
                                                    <Input :disabled="canedit" placeholder="请输入证件号码"></Input> 
                                                </Form-item> 
                                            </Col>
                                            <Col span="24">
                                                <Form-item label="出生日期">
                                                    <DatePicker :disabled="canedit" type="date" placeholder="请选择"></DatePicker> 
                                                </Form-item> 
                                            </Col>
                                            <Col span="24">
                                                <Form-item label="工作单位">
                                                    <Input :disabled="canedit" placeholder="请输入工作单位"></Input> 
                                                </Form-item> 
                                            </Col>
                                            <Col span="24">
                                                <Form-item label="职业/工种">
                                                    <Input :disabled="canedit" placeholder="请输入职业/工种"></Input> 
                                                </Form-item> 
                                            </Col>
                                            <Col span="12">
                                                <Form-item label="邮编">
                                                    <Input :disabled="canedit" placeholder="请输入邮编"></Input> 
                                                </Form-item> 
                                            </Col>
                                            <Col span="12">
                                                <Form-item label="Email">
                                                    <Input :disabled="canedit" placeholder="请输入Email"></Input> 
                                                </Form-item> 
                                            </Col>
                                            <Col span="24">
                                                <Form-item label="详细地址">
                                                    <Input :disabled="canedit" placeholder="请输入详细地址"></Input> 
                                                </Form-item> 
                                            </Col>
                                        </Row>
                                    </Form>
                                </div>
                            </div>                            
                        </div>
                    </Col>
                </Row> 
            </div>                      
            <div slot="footer"></div>          
        </Modal>
        <Modal v-model="importemployee" :mask-closable='closeable' width="860" title="导入员工信息" :loading="loading">
            <div class="modal-body">            
                <Row>
                    <Col span="24">
                        <div class="import-left">
                            <div class="common-box-body">
                                <div class="import-search">
                                    <Form ref="formInline">
                                        <Form-item label="姓名">
                                            <Input placeholder="请输入姓名" v-model="searchemploy">
                                                <Button slot="append" @click="searchemp" type="primary" icon="icon iconfont icon-sousuo"></Button>
                                            </Input>
                                        </Form-item> 
                                    </Form>
                                </div> 
                                <div class="import-list">
                                    <Table :loading="tableloading" :show-header=false stripe height="415" :columns="columns" :data="emplist"></Table>
                                </div>                             
                            </div>
                        </div> 
                    </Col>
                </Row> 
            </div>                      
            <div slot="footer"></div>          
        </Modal>  
        <Spin size="large" fix v-if="spinShow"></Spin>     
    </div>
</template>

<script>
import productTitle from '../../components/productTitle'
import { formatTime } from '../../libs/time'
import { getByName , getById} from '../../api/employee'
import { AgentByName } from '../../api/customer'
import { proGetByName } from '../../api/product_v2' 
import { parteGetByName } from '../../api/parter'
import { updateInsure,getInsureDetail  } from '../../api/policy'
export default {
    data() {

        return {
            tableloading:false,
            spinShow:true,
            addcustomer:false,
            importcustomer:false,
            importemployee:false,
            importtype:'',
            canedit:true,
            closeable:false,
            loading:true,
            proloading:false,
            options1:[],
            comoptions:[],
            prolist:[],
            renewalInsure:{},
            searchemploy:'',
            searchcustom:'',
            //录单员
            entering:{
                job_code:'',
                name:'',
                datetime:formatTime(new Date(),'yyyy-MM-dd'),
                date:formatTime(new Date(),'yyyy-MM-dd')
            },
            //业务员
            agent:{
                oid:'',
                oname:'',
                dept_id:'',
                dept_name:'',
                rank_id:'',
                rank_name:'',
                name:'',
                eid :'',
                job_code:'',
                leader_name:'',
                leader_id :'',
                rec_name:'',
                rec_id:''
            },
            //保单信息
            policyform:{
                cid:'',
                status:'1',
                cname:'',
                name:'',
                insure_num:'',
                pay_type:'',
                premium:'',
                is_short:'2',
                insure_datetime:formatTime(new Date(),'yyyy-MM-dd'),
                insure_date:formatTime(new Date(),'yyyy-MM-dd'),
                withdraw_datetime:'',
                withdraw_date:'',
            },
            //投保人信息
            applicant:{
                customer_id:'',
                name:'',
                cardName:'身份证',
                cardNum:'',
                mobile:'',
                sex:'',
                birthday:'',
                birthdaytime:'',
                company:'',
                profession:'',
                postcode:'',
                email:''
            },
            //被保人
            policyDetail:{
                insureds:[
                    {
                        relation:'本人',
                        canedit:true,
                        name:'',
                        cardName:'身份证',
                        cardNum:'',
                        mobile:'',
                        sex:'',
                        birthday:'',
                        birthdaytime:'',
                        company:'',
                        profession:'',
                        insurances:[
                            {
                                id:'',
                                name:'',
                                period:'',
                                period_arry:[],
                                pay_period:'',
                                pay_period_arry:[],
                                premium:'', 
                                type:'保险金额',
                                amount :''
                            }
                        ],
                        beneficiary_type:'指定受益',
                        beneficiary:[
                            {
                                name:'',
                                cardName:'身份证',
                                cardNum:'',
                                mobile:'',
                                relation:'',
                                sex:'',
                                birthday:'',
                                birthdaytime:'',
                                order:'',
                                scale:''
                            }
                        ]
                    }
                ]
            },
            columns: [
                {
                    title: '姓名',
                    key: 'name'
                },
                {
                    title: '工号',
                    key: 'job_code',
                    render: (h, params) => {
                        return h('div', {},'工号：'+params.row.job_code);
                    }
                },
                {
                    title: '操作',
                    key: 'address',
                    align:"center",
                    width:100,
                    render: (h, params) => {
                        return h('div', [
                            h('Button', {
                                props: {
                                    type: 'primary',
                                    size: 'small'
                                },
                                style: {
                                    marginRight: '5px'
                                },
                                on: {
                                    click: () => {
                                        this.impempbtn(params.row.id)
                                    }
                                }
                            }, '导入')
                        ]);
                    }
                }
            ],
            columnsuser:[
                {
                    title: '姓名',
                    key: 'name'
                },               
                {
                    title: '操作',
                    key: 'address',
                    align:"center",
                    width:100,
                    render: (h, params) => {
                        return h('div', [
                            h('Button', {
                                props: {
                                    type: 'primary',
                                    size: 'small'
                                },
                                style: {
                                    marginRight: '5px'
                                },
                                on: {
                                    click: () => {
                                        this.impempbtn(params.row.id)
                                    }
                                }
                            }, '导入')
                        ]);
                    }
                }
            ],
            userlist:[
                
            ],
            emplist:[

            ],
            entering_ruleValidate: {
                job_code:[
                    { required: true, message: '请填写录单员工号', trigger: 'change' }
                ],
                name: [
                    { required: true, message: '请填写录单员姓名', trigger: 'change' }
                ],  
                datetime: [
                    { required: true, type: 'date', message: '请选择录单时间', trigger: 'change' }
                ],              
            },
            agent_ruleValidate: {
                // oname:[
                //     { required: true, message: '请选择机构', trigger: 'change' }
                // ],
                // dept_name: [
                //     { required: true, message: '请选择部门', trigger: 'change' }
                // ],
                // rank_name : [
                //     { required: true, message: '请选择职级', trigger: 'change' }
                // ], 
                job_code  : [
                    { required: true, message: '请选择工号', trigger: 'change' }
                ], 
                name: [
                    { required: true, message: '请选择姓名', trigger: 'change' }
                ],
            },
            policy_ruleValidate:{
                cid:[
                    { required: true, message: '请填写保险公司',transform(value) {
                    return value.toString();
                    }, trigger: 'change' }
                ],
                insure_datetime:[
                    { required: true, type:'date', message: '请填写投保时间', trigger: 'change' }
                ],
                name: [
                    { required: true, message: '请填写保险计划', trigger: 'blur' }
                ],
                insure_num: [
                    { required: true, message: '请填写保单号', trigger: 'blur' }
                ], 
                pay_period: [
                    { required: true, message: '请填写交费期间', trigger: 'change' }
                ], 
                pay_type: [
                    { required: true, message: '请填写交费方式', trigger: 'change' }
                ], 
                status: [
                    { required: true, message: '请选择保单状态', trigger: 'change' }
                ],
                withdraw_datetime: [
                     { required: true, type:'date', message: '请填写撤单时间', trigger: 'change' }
                ],
                premium: [
                    { required: true, type:'number',transform(value) {
                    return parseFloat(value);
                    }, message: '请正确填写保费', trigger: 'blur' }
                ],
            },
            applicant_ruleValidate:{
                name:[
                    { required: true, message: '请填写姓名', trigger: 'blur' }
                ],
                cardName: [
                    { required: true, message: '请选择证件类型', trigger: 'change' }
                ],
                cardNum: [
                    { required: true, pattern: /^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/, message: '请填写证件号', trigger: 'blur' }
                ], 
                mobile: [
                    { required: true, pattern: /^1[3|4|5|6|7|8|9][0-9]\d{8}$/, message: '请填写手机号', trigger: 'blur' }
                ],  
                sex: [
                    { required: true, message: '请选择性别', trigger: 'change' }
                ],
                birthdaytime: [
                    { required: true, type:'date', message: '请选择日期', trigger: 'change' }
                ],
                postcode:[
                    { pattern: /^[0-9]{6}$/, message: '请正确填写邮编', trigger: 'change' }
                ],
                email: [
                    { type:'email', message: '请正确填写email', trigger: 'change' }
                ],
            },
            insured_ruleValidate:{
                name:[
                    { required: true, message: '请填写姓名', trigger: 'blur' }
                ],
                cardName: [
                    { required: true, message: '请选择证件类型', trigger: 'change' }
                ],
                cardNum: [
                    { required: true, pattern: /^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/, message: '请填写证件号', trigger: 'blur' }
                ], 
                mobile: [
                    { required: true, pattern: /^1[3|4|5|6|7|8|9][0-9]\d{8}$/, message: '请填写手机号', trigger: 'blur' }
                ],
                sex: [
                    { required: true, message: '请选择性别', trigger: 'blur,change' }
                ],
                birthdaytime: [
                    { required: true, type:'date', message: '请选择生日', trigger: 'blur,change' }
                ],
                period: [
                    { required: true, message: '请选择保险期间', trigger: 'change' }
                ],
                pay_period: [
                    { required: true, message: '请选择交费期间', trigger: 'change' }
                ],
                premium: [
                    { required: true, message: '请填写保费', trigger: 'blur' }
                ],
                amount: [
                    { required: true, message: '请填写', trigger: 'blur' }
                ],
                type: [
                    { required: true, message: '请选择', trigger: 'change' }
                ],
            }
        }
    },
    components: {
        productTitle
    },
    computed: {
        slidetoggle(){
            return this.$store.state.sildeshow
        },
        statustag(){
            if(this.policyform.status == "3"){
                return true
            }else{
                return false
            }
        },
        policypay_period(){
            let policyarry = []
            for(var i=0;i<this.policyDetail.insureds.length;i++){
                for(var j=0;j<this.policyDetail.insureds[i].insurances.length;j++){
                    policyarry.push(this.policyDetail.insureds[i].insurances[j].pay_period)
                }
            }
            let _arry = Array.from(new Set(policyarry))
            _arry = _arry.filter(function(item){
                return item !== ''
            });
            return _arry
        }
    },
    mounted () {
        this.cominit()
        this.getDetial()
    },
    methods: {
        cominit(){
            new Promise((resolve, reject) => {
                let _params = {
                    name:''
                }
                parteGetByName(_params).then(response => {
                        console.log(response.data)
                        if (response.data.err == 0) {                           
                            this.comoptions = response.data.data;
                        } else {
                            this.$Message.error(response.data.info);
                        }
                        resolve();
                    }).catch(error => {
                        reject(error);
                    });
            });
        },
        surebtn(){

        },        
        getDetial(){
            console.log(this.$route.params.id)
            let _params = {
                policy_id :this.$route.params.id
            }

                       
            new Promise((resolve, reject) => {                        
                getInsureDetail(_params).then(response => {
                    console.log(response.data)
                    this.spinShow = false
                    if (response.data.err == 0){
                        this.entering = response.data.data.entering
                        this.entering.datetime = response.data.data.entering.date
                        this.agent = response.data.data.agent
                        this.applicant = response.data.data.applicant
                        this.applicant.sex = response.data.data.applicant.sex.toString()
                        this.applicant.birthdaytime = response.data.data.applicant.birthday                                    
                        this.policyform = response.data.data.policyform                       
                        this.policyform.status = response.data.data.policyform.status.toString() 
                        //this.policyform.cid = response.data.data.policyform.cid.toString() 
                        this.policyform.insure_datetime = response.data.data.policyform.insure_date
                        this.policyform.is_short = response.data.data.policyform.is_short.toString() 
                        this.policyDetail.insureds = response.data.data.insureds
                        let _length = response.data.data.insureds.length
                        for(var i=0;i<_length;i++){
                            this.policyDetail.insureds[i].birthdaytime = this.policyDetail.insureds[i].birthday
                            this.policyDetail.insureds[i].sex = this.policyDetail.insureds[i].sex.toString()
                            if(this.policyDetail.insureds[i].beneficiary&&this.policyDetail.insureds[i].beneficiary.length > 0){
                                let _len = this.policyDetail.insureds[i].beneficiary.length                               
                                for(var j=0;j<_len;j++){                                   
                                this.policyDetail.insureds[i].beneficiary[j].birthdaytime =  this.policyDetail.insureds[i].beneficiary[j].birthday
                                this.policyDetail.insureds[i].beneficiary[j].sex = this.policyDetail.insureds[i].beneficiary[j].sex.toString()                                   
                                }                                                             
                            }else{
                                this.policyDetail.insureds[i].beneficiary = []
                            }                                          
                        }                                           
                    } else {
                        this.$Message.error(response.data.info);
                    }
                    resolve();
                }).catch(error => {
                    this.spinShow = false
                    reject(error);
                });
            });
        }, 
        companychange(item){
            //console.log(item)
            if(item.label){
                this.policyform.cname = item.label
            }     
        },
        prochange(e,pindex,index){
            if(e.label){
                console.log(e)
                console.log(pindex)
                console.log(index)
                let items = this.prolist.filter(item=>item.label==e.label)
                console.log(items)
                if(items.length > 0){
                    this.policyDetail.insureds[pindex].insurances[index].period = ''
                    this.policyDetail.insureds[pindex].insurances[index].pay_period = ''
                    this.policyDetail.insureds[pindex].insurances[index].period_arry = items[0].period
                    this.policyDetail.insureds[pindex].insurances[index].pay_period_arry = items[0].pay_period
                }               
            }                     
        },
        //远程请求保险公司
        remoteCom(query){
            if (query !== '') {
                this.proloading = true;
                setTimeout(() => {
                    
                    new Promise((resolve, reject) => {
                        let _params = {
                            name:query,
                        }
                        parteGetByName(_params).then(response => {
                            console.log(response.data)
                            if (response.data.err == 0){
                                 this.proloading = false;
                                const list = response.data.data.map(item => {
                                    return {
                                        value: item.cid,
                                        label: item.name,
                                        pay_period:item.pay_period,
                                        period:item.period
                                    };
                                });
                                this.comoptions = list.filter(item => item.label.toLowerCase().indexOf(query.toLowerCase()) > -1);                   
                            } else {
                                this.$Message.error(response.data.info);
                            }
                            resolve();
                        }).catch(error => {
                            reject(error);
                        });
                    });                   
                }, 200);
            } else {
                this.comoptions = [];
            }
        },
        //远程请求险种
        remoteMethod1 (query) {
            console.log(query)
            if (query !== '') {
                this.proloading = true;
                setTimeout(() => {
                    let _params = {
                        name:query,
                    }
                    new Promise((resolve, reject) => {
                        
                        proGetByName(_params).then(response => {
                            console.log(response.data)
                            if (response.data.err == 0){
                                 this.proloading = false;
                                const list = response.data.data.map(item => {
                                    return {
                                        value: item.id,
                                        label: item.name,
                                        pay_period:item.pay_period,
                                        period:item.period
                                    };
                                });
                                this.prolist = list
                                this.options1 = list.filter(item => item.label.toLowerCase().indexOf(query.toLowerCase()) > -1);                   
                            } else {
                                this.$Message.error(response.data.info);
                            }
                            resolve();
                        }).catch(error => {
                            reject(error);
                        });
                    });                   
                }, 200);
            } else {
                this.options1 = [];
            }
        },
        //删除被保人
        delinsured(index){           
            this.policyDetail.insureds.splice(index,1)
            console.log(this.policyDetail.insureds.length)
            if(this.policyDetail.insureds.length == 0){
                this.addinsured()
            }
        },
        //追加被保人
        addinsured(){
            this.policyDetail.insureds.push(
                {
                    relation:'本人',
                    canedit:true,
                    name:'',
                    cardName:'身份证',
                    cardNum:'',
                    mobile:'',
                    sex:'',
                    birthday:'',
                    company:'',
                    profession:'',
                    insurances:[
                        {
                            name:'',
                            period:'',
                            pay_period:'',
                            premium:'', 
                            type:'保险金额',
                            amount :''
                        }
                    ],
                    beneficiary_type:'指定受益',
                    beneficiary:[
                        {
                            name:'',
                            cardName:'身份证',
                            cardNum:'',
                            mobile:'',
                            relation:'',
                            sex:'',
                            birthday:'',
                            order:'',
                            scale:''
                        }
                    ]
                }
            )
        },
        //添加险种
        addpro(pindex,sindex){
            this.policyDetail.insureds[pindex].insurances.push(
                {
                    name:'',
                    period:'',
                    pay_period:'',
                    premium:'', 
                    type:'保险金额',
                    amount :''
                }
            )
        },
        //删除险种
        delpro(pindex,sindex){
            this.policyDetail.insureds[pindex].insurances.splice(sindex,1)
            if(this.policyDetail.insureds[pindex].insurances.length == 0){
                this.addpro(pindex,sindex)
            }
        },
        //追加受益人
        addbenefit(pindex){
            this.policyDetail.insureds[pindex].beneficiary.push(
                {
                    name:'',
                    cardName:'身份证',
                    cardNum:'',
                    mobile:'',
                    relation:'',
                    sex:'',
                    birthday:'',
                    order:'',
                    scale:''
                }
            )
        },
        //删除受益人
        delbenefit(pindex,bindex){
            this.policyDetail.insureds[pindex].beneficiary.splice(bindex,1)
            if(this.policyDetail.insureds[pindex].beneficiary.length == 0){
                this.addbenefit(pindex)
            }
        },
        radiochange(obj,index){
            if(obj !== "本人"){
                this.policyDetail.insureds[index].canedit = false
            }else{
                this.policyDetail.insureds[index].canedit = true
            }
        },
        benefitchange(obj,index){
            if(obj == "法定受益"){
                this.policyDetail.insureds[index].beneficiary = []
            }else{
                this.policyDetail.insureds[index].beneficiary = [
                    {
                        name:'',
                        cardName:'身份证',
                        cardNum:'',
                        mobile:'',
                        relation:'',
                        sex:'',
                        birthday:'',
                        order:'',
                        scale:''
                    }
                ]
            }
        },
        //时间转换
        datachange(date,obj,param){
            obj[param] = date
        },
        importEmployee(type){
            this.importemployee = true
            this.importtype = type
        },
        importapplicant(type){
            this.importcustomer = true
            this.importtype = type
        },
        //获取险种
        proGetByName(){

        },
        //获取客户信息
        getcustomer(){
            if(!this.agent.eid){
                this.$Message.error("请先导入业务员信息")
                return false
            }
            new Promise((resolve, reject) => {
                let _params = {
                    name:this.searchcustom,
                    agent_uid:this.agent.eid
                }
                AgentByName(_params).then(response => {
                    console.log(response.data)
                    if (response.data.err == 0){
                                             
                    } else {
                        this.$Message.error(response.data.info);
                    }
                    resolve();
                }).catch(error => {
                    reject(error);
                });
            });
        },

        //导入员工
        impempbtn(id){
            this.getemployee(id)
        },
        //获取员工详细信息
        getemployee(id){
            new Promise((resolve, reject) => {
                let _params = {
                    id:id
                }
                getById(_params).then(response => {
                    console.log(response.data)
                    if (response.data.err == 0){
                       if(this.importtype == 1){
                           this.entering = Object.assign(this.entering,response.data.data)
                       }
                       if(this.importtype == 2){
                           this.agent = Object.assign(this.agent,response.data.data)
                       }
                       this.importemployee = false
                    } else {
                        this.$Message.error(response.data.info);
                    }
                    resolve();
                }).catch(error => {
                    reject(error);
                });
            });
        },
        //员工搜索 by name
        searchemp(){
           // this.searchemploy
           this.tableloading = true
            new Promise((resolve, reject) => {
                let _params = {
                    name:this.searchemploy
                }
                getByName(_params).then(response => {
                    console.log(response.data)
                    this.tableloading = false
                    if (response.data.err == 0) {
                        this.emplist = response.data.data
                    } else {
                        this.$Message.error(response.data.info);
                    }
                    resolve();
                }).catch(error => {
                    this.tableloading = false
                    reject(error);
                });
            });
        },
        sendpolicy(){
            //'entering','agent','policyform','applicant'
            let successtag = 0
            let formarry = ['entering','agent','policyform','applicant']
            for(var i=0;i<formarry.length;i++){
                this.$refs[formarry[i]].validate((valid) => {
                if (valid) {                       
                    } else {
                        successtag++
                    }
                })
            }
            console.log(successtag)
            if(successtag == 0){
                let _insureds = this.policyDetail.insureds
                for(var i=0;i<_insureds.length;i++){
                    if(_insureds[i].relation == "本人"){
                        _insureds[i].name = this.applicant.name
                        _insureds[i].cardName  = this.applicant.cardName 
                        _insureds[i].cardNum  = this.applicant.cardNum 
                        _insureds[i].mobile = this.applicant.mobile
                        _insureds[i].sex  = this.applicant.sex 
                        _insureds[i].birthday = this.applicant.birthday
                        _insureds[i].birthdaytime = this.applicant.birthdaytime
                        _insureds[i].company = this.applicant.company
                        _insureds[i].profession = this.applicant.profession 
                    }
                }
            }
            for(var i =0 ;i<this.$refs['insureds'].length;i++){
                this.$refs['insureds'][i].validate((valid) => {
                if (valid) {                   
                    } else {
                        console.log(i)
                        successtag++
                    }
                })
            }
            console.log(successtag)
            if(successtag == 0){
                this.spinShow = true
                let _obj = {}
                _obj.entering = this.entering
                _obj.agent = this.agent
                _obj.policyform =this.policyform
                _obj.applicant = this.applicant
                _obj.insureds = this.policyDetail.insureds
                _obj.policy_id = this.$route.params.id
                // for(var i=0;i<_obj.insureds.length;i++){
                //     if(_obj.insureds[i].relation == "本人"){
                //         delete _obj.insureds[i].name
                //         delete _obj.insureds[i].cardName
                //         delete _obj.insureds[i].cardNum
                //         delete _obj.insureds[i].mobile
                //         delete _obj.insureds[i].sex
                //         delete _obj.insureds[i].birthday
                //         delete _obj.insureds[i].company
                //         delete _obj.insureds[i].profession
                //     }else{
                //         if(!_obj.insureds[i].name){
                //             _obj.insureds[i].name = ''
                //             _obj.insureds[i].cardName= ''
                //             _obj.insureds[i].cardNum = ''
                //             _obj.insureds[i].mobile = ''
                //             _obj.insureds[i].sex = ''
                //             _obj.insureds[i].birthday = ''
                //             _obj.insureds[i].company = ''
                //             _obj.insureds[i].profession = ''
                //         }
                //     }
                // }
                console.log(_obj)
                console.log(JSON.stringify(_obj))
                new Promise((resolve, reject) => {
                    updateInsure(_obj).then(response => {
                        console.log(response.data)
                        if (response.data.err == 0) {
                        // this.emplist = response.data.data
                            this.$Message.success(response.data.info);
                            this.$router.push({ name: 'insure_policy' });
                        } else {
                            this.spinShow = false
                            this.$Message.error(response.data.info);
                        }
                        resolve();
                    }).catch(error => {
                        this.spinShow = false
                        reject(error);
                    });
                });  
            }else{
                this.$Message.error("请完善必填信息！");
            }                     
        },
        resetform(){
            this.$refs['entering'].resetFields();
            this.$refs['agent'].resetFields();
            this.$refs['policyform'].resetFields();
            this.$refs['applicant'].resetFields();
            //this.$refs['insureds'][0].resetFields();
            //this.$refs['insureds'].resetFields();
            //console.log(this.$refs['insureds'])
            for(var i =0 ;i<this.$refs['insureds'].length;i++){
                this.$refs['insureds'][i].resetFields();
            }
            console.log(this.$refs['insureds'][0])
            console.log(this.$refs)
        }
    }
}
</script>
